<template>
    <div>
        <el-button type="primary" plain @click="add">添加</el-button>
        <el-table :data="secklist" row-key="id" border style="width: 100%">
            <el-table-column prop="title" label="活动名称"> </el-table-column>
            <el-table-column prop="begintime" label="开始事件">
                <template slot-scope="scope">
                    <div>
                        {{ scope.row.begintime | toDate }}
                    </div>
                </template>
            </el-table-column>
            <el-table-column prop="endtime" label="结束事件">
                <template slot-scope="scope">
                    <div>
                        {{ scope.row.endtime | toDate }}
                    </div>
                </template>
            </el-table-column>
            <el-table-column prop="status" label="状态">
                <template slot-scope="scope">
                    <el-tag type="success" plain size="middle">{{
                        scope.row.status == 1 ? "启用" : "禁用"
                    }}</el-tag>
                </template>
            </el-table-column>
            <el-table-column prop="operate" label="操作" ref="seck">
                <template slot-scope="scope">
                    <el-button
                        type="primary"
                        icon="el-icon-edit"
                        circle
                        @click="edit(scope.row)"
                    ></el-button>
                    <el-button
                        type="danger"
                        icon="el-icon-delete"
                        circle
                        @click="del(scope.row.id)"
                    ></el-button>
                </template>
            </el-table-column>
        </el-table>
    </div>
</template>

<script>
//引入vuex
import Vuex from "vuex";
export default {
    data() {
        return {};
    },
    methods: {
        //引入 活动列表 接口
        ...Vuex.mapActions({
            getlist: "seck/secklist_a",
            seckdel: "seck/seckdelete_a",
            seckinfo: "seck/seckinfo_a",
        }),
        //点击添加
        add() {
            this.$emit("changeBtn", true);
        },
        //点击编辑
        edit(row) {
            this.$emit("changeBtn", false); //点击编辑 不是添加按钮
            this.seckinfo(row.id);
            this.$store.dispatch("goods/goodslist_a", {
                fid: row.first_cateid,
                sid: row.second_cateid,
            });
            //点击编辑 触发seckill组件的方法，等seckill触发函数
            this.$emit("setDate",[new Date(Number(row.begintime)), new Date(Number(row.endtime))])
        },
        //点击删除
        del(id) {
            //点击弹出
            this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning",
            })
                .then(() => {
                    this.seckdel(id);
                })
                .catch(() => {
                    this.$message({
                        type: "info",
                        message: "已取消删除",
                    });
                });
        },
    },
    mounted() {
        //调用
        this.getlist();
    },
    computed: {
        //引入 活动列表数据
        ...Vuex.mapGetters({
            seckform: "seck/getseckinfo",
            secklist: "seck/getsecklist",
        }),
    },
    filters: {
        toDate(n) {
            let date = Number(n)//转换成数字类型
            //把时间戳 转换成 "2021/1/21 24:02:00"这个格式
            date = new Date(date).toLocaleString('chinese',{hour12:false})
            //把时间 转成 "2021-1-21 24:00:00" 格式
            date = date.split('/').join('-')
            return date;
        },
    },
};
</script>

<style scoped></style>
